'use strict';
let Response = require('../../../model/Response');
let RestifyProxy = require('../../../util/RestifyProxy');
let CustomPageBean = require('../../../model/CustomPageBean');
let organizeService = require('../../../service/system/organizeService.js');
let logger = require('../../../util/LoggerUtil').logger('organizeController.js');

/**
 * 系统设置-组织机构管理—页面
 */
module.exports.organizePage = function () {
    let response = new Response();
    response.render('back/system/organize/organize');//html路径
    this.resolve(response);
};

/**
 * 系统设置-组织机构管理——列表
 */
module.exports.organizeList = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await organizeService.organizeList(this, params);
        let pageBean = new CustomPageBean(result);
        response.send(pageBean);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*组织机构管理-新增页面-确认按钮*/
module.exports.organizeAdd = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await organizeService.organizeAdd(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};

/*组织机构管理-修改页面-数据*/
module.exports.organizeModifydata = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await organizeService.organizeModifydata(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/*组织机构管理-修改页面-确认按钮*/
module.exports.organizeModify = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await organizeService.organizeModify(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/*组织机构管理-删除按钮*/
module.exports.organizeDelete = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await organizeService.organizeDelete(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
/**
 * 系统设置-组织机构管理——tree数据
 */
module.exports.organizeTree = async function () {
    let req = this.req;
    let params = req.body;
    let response = new Response();
    try {
        let result = await organizeService.organizeTree(this, params);
        response.send(result);
    } catch (error) {
        logger.error(error);
    }
    this.resolve(response);
};
